import 'package:dio/dio.dart';

class DioManager {
  late Dio dio;

  DioManager._internal() {
    dio = Dio();

    httpProxy();
  } // 私有构造函数

  static final DioManager _instance = DioManager._internal(); //唯一单例 类私有
  factory DioManager() => _instance; // 工厂模式获取单例
  static DioManager get instance => _instance; //静态变量获取单例

  Future<Response<T>> get<T>(
    String path, {
    Map<String, dynamic>? queryParameters,
    Options? options,
    CancelToken? cancelToken,
    ProgressCallback? onReceiveProgress,
  }) {
    return dio.get(
      path,
      queryParameters: queryParameters,
      options: options,
      cancelToken: cancelToken,
      onReceiveProgress: onReceiveProgress,
    );
  }

  Future<Response<T>> post<T>(
    String path, {
    data,
    Map<String, dynamic>? queryParameters,
    Options? options,
    CancelToken? cancelToken,
    ProgressCallback? onSendProgress,
    ProgressCallback? onReceiveProgress,
  }) {
    return dio.post(
      path,
      data: data,
      queryParameters: queryParameters,
      options: options,
      cancelToken: cancelToken,
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
    );
  }

  void httpProxy() {}
}
